#include "StdAfx.h"
#include "SgRegularPolygon.h"
#include "graphics/GrVector.h"

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

CSgRegularPolygon::CSgRegularPolygon(void)
{
	m_normal[0] = 0.0;
	m_normal[1] = 0.0;
	m_normal[2] = 1.0;
}

CSgRegularPolygon::~CSgRegularPolygon(void)
{
}

void CSgRegularPolygon::SetNormal(GLdouble *n)
{
	m_normal[0] = n[0];
	m_normal[1] = n[1];
	m_normal[2] = n[2];
}

void CSgRegularPolygon::SetProperties(int sides, double radius )
{
	m_Sides = sides;
	m_Radius = radius;
}

void CSgRegularPolygon::Render(void){

	glBegin(GL_POLYGON);
		
		for (double i = 0; i < m_Sides; i++)
		{
			glNormal3dv(m_normal);
			GLdouble start[] = {m_Radius*cos(i*2*M_PI/m_Sides+2*M_PI/(m_Sides*2.0)),0.0,m_Radius*sin(i*2*M_PI/m_Sides+2*M_PI/(m_Sides*2.0))};
			GLdouble end[] = {m_Radius*cos((i+1)*2*M_PI/m_Sides+2*M_PI/(m_Sides*2.0)),0.0,m_Radius*sin((i+1)*2*M_PI/m_Sides+2*M_PI/(m_Sides*2.0))};
			glVertex3dv(start);
			glVertex3dv(end);
		}
	glEnd();

}